<template>
  <div class="home-card">
    <div class="home-card-inner">
      <div class="user-info">
        <div class="avatar-wrapper">
          <ImageView
            :src="avatar"
            round
          ></ImageView>
        </div>
        <div class="nickname">{{nickname}}</div>
        <div class="shelf-text">书架共有{{num}}本好书</div>
        <div class="round-item"></div>
        <div class="shelf-text">特别精选</div>
      </div>
      <div class="book-info">
        <div
          class="book-wrapper"
          v-for="(item,index) in bookList"
          :key="index"
          @click="onBookClick(item)"
        >
          <div class="book-img-wrapper">
            <ImageView :src="item.cover"></ImageView>
          </div>
        </div>
        <div
          class="shelf-wrapper"
          @click="gotoShelf"
        >
          <div class="shelf">书架</div>
          <van-icon
            name="arrow"
            class="arrow"
            size="11px"
            color="#828489"
          />
        </div>
      </div>
      <div
        class="feedback-wrapper"
        @click="onFeedBackClick"
      ><span>反馈</span></div>
    </div>
    <van-dialog id="van-dialog" />
  </div>
</template>

<script>
import ImageView from '../base/ImageView'
import Dialog from 'vant-weapp/dist/dialog/dialog'
export default {
  components: { ImageView },
  props: {
    data: Object,
    hasSign: {
      type: Boolean,
      default: false
    },
    signDay: {
      type: Number,
      default: 0
    }
  },
  computed: {
    // 因为数据从父组件传递过来是异步的，所以需要这样写(等有数据了，才赋值)
    avatar () {
      return (this.data && this.data.userInfo && this.data.userInfo.avatarUrl) || ''
    },
    nickname () {
      return (this.data && this.data.userInfo && this.data.userInfo.nickName) || ''
    },
    num () {
      return (this.data && this.data.num) || '0'
    },
    bookList () {
      return (this.data && this.data.bookList) || []
    }
  },
  methods: {
    // 跳转到书架列表
    gotoShelf () {
      this.$router.push({ path: '/pages/shelf/main' })
    },
    // 图书点击事件
    onBookClick (e) {
      console.log(e)
      this.$emit('onBookClick', e)
    },
    // 签到事件
    sign () { },
    // 反馈单击事件
    onFeedBackClick () {
      Dialog.confirm({
        title: '反馈',
        message: '您是否确认提交反馈信息',
        confirmButtonText: '是',
        cancelButtonText: '否',
        closeOnClickOverlay: true
      }).then(() => {
        console.log('是')
      }).catch(() => {
        console.log('否')
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.home-card {
  background-image: linear-gradient(-90deg, #54575f 0%, #595b60 100%);
  border-radius: 30rpx;
  margin: 24rpx 18rpx 0;
  .home-card-inner {
    position: relative;
    padding: 32rpx 26rpx;
    box-sizing: border-box;
    .user-info {
      display: flex;
      align-items: center;
      .avatar-wrapper {
        height: 50rpx;
        width: 50rpx;
        margin-right: 8rpx;
      }
      .nickname {
        padding-left: 8rpx;
        font-family: PingFangSC-Regular;
        font-size: 28rpx;
        color: #ffffff;
      }
      .shelf-text {
        opacity: 0.7;
        font-family: PingFangSC-Regular;
        font-size: 28rpx;
        color: #ffffff;
        padding: 0 12rpx;
      }
      .round-item {
        background: #a2a2a2;
        width: 8rpx;
        height: 8rpx;
        border-radius: 50%;
        margin: 0 8rpx;
      }
    }
    .book-info {
      display: flex;
      margin-left: -28rpx;
      margin-top: 14rpx;
      .book-wrapper {
        flex: 1;
        display: flex;
        justify-content: space-around;
        .book-img-wrapper {
          height: 220rpx;
          width: 150rpx;
        }
      }
      .shelf-wrapper {
        display: flex;
        align-items: center;
        .shelf {
          opacity: 0.6;
          font-size: 22rpx;
          width: 22rpx;
          word-break: break-word;
          color: #ffffff;
        }
      }
    }
    .feedback-wrapper {
      position: absolute;
      width: 88rpx;
      height: 48rpx;
      line-height: 48rpx;
      text-align: center;
      right: 0;
      top: 30rpx;
      background: #707070;
      border-radius: 200px 0 0 200px;
      span {
        font-size: 22rpx;
        color: #ffffff;
      }
    }
  }
}
</style>